#include <stdio.h>

int strlen(const char* s)
{
  int i;
  for(i=0; *s!='\0'; ++s,++i);
  return i;
}

char* strstr(const char* str0, const char* str1)
{
  int n, m, i, j;
  n = strlen(str0);
  m = strlen(str1);
  for(i = 0; i<=n-m;++i) {
    for(j = 0; j<m && str0[i+j]==str1[j]; ++j);
    if(j == m)
      return (char*)str0+i; //matched
  }
  return NULL;//no match
}

int main()
{
  char s0[] = "";
  char s1[] = "abcdef";
  char s2[] = "cdef";
  char s3[] = "efg";
  char s4[] = "bcd";
  char* s;

  printf("%s\n",strstr(s1,s2));
  printf("%s\n",strstr(s1,s0));
  if( (s=strstr(s1,s3))!=NULL)
    printf("%s\n",s);
  printf("%s\n",strstr(s1,s4));
  printf("%s\n",strstr(s1,s1));

  return 0;
}
